#include <iostream>
#include "BlackQueue.hpp"
#include <unistd.h>
#include <string>
using namespace BlockQueueModule;

pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;

void *codea(void *rage)
{
    std::string str = static_cast<const char *>(rage);
    while (true)
    {
        pthread_mutex_lock(&mutex);
        pthread_cond_wait(&cond,&mutex);
        std::cout<<str<<std::endl;
        pthread_mutex_unlock(&mutex);
    }
}

void* myEQueue(void* arge)
{
   BlockQueue<int>* re=static_cast<BlockQueue<int>*>(arge);
    int lock=10;
    while (true)
    {
        sleep(2);
        re->EQueue(lock);
        printf("_productor_cond---%d\n",lock);
        lock++;
    }
}

void* mypop(void* arge)
{
    BlockQueue<int>* re=static_cast<BlockQueue<int>*>(arge);
    while (true)
    {
        int lock;
        re->Pop(lock);
        printf("_consumer_cond---%d\n",lock);
    }
}

int main()
{
    BlockQueue<int>* q=new BlockQueue<int>();
   pthread_t c1,c2, p1, p2, p3;
    pthread_create(&c1, nullptr, mypop, q);
    pthread_create(&c2, nullptr, mypop, q);
    pthread_create(&p1, nullptr,myEQueue, q);
    pthread_create(&p2, nullptr, myEQueue, q);
    pthread_create(&p3, nullptr, myEQueue, q);

    pthread_join(c1, nullptr);
    pthread_join(c2, nullptr);
    pthread_join(p1, nullptr);
    pthread_join(p2, nullptr);
    pthread_join(p3, nullptr);
    delete q;
    return 0;
}